package com.legal.aid.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.legal.aid.common.annotation.Log;
import com.legal.aid.common.core.controller.BaseController;
import com.legal.aid.common.core.domain.AjaxResult;
import com.legal.aid.common.enums.BusinessType;
import com.legal.aid.system.domain.LawRegulation;
import com.legal.aid.system.service.ILawRegulationService;
import com.legal.aid.common.utils.poi.ExcelUtil;
import com.legal.aid.common.core.page.TableDataInfo;

/**
 * 法律法规Controller
 * 
 * @author ruoyi
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/system/lawRegulation")
public class LawRegulationController extends BaseController
{
    @Autowired
    private ILawRegulationService lawRegulationService;

    /**
     * 查询法律法规列表
     */
    @PreAuthorize("@ss.hasPermi('system:lawRegulation:list')")
    @GetMapping("/list")
    public TableDataInfo list(LawRegulation lawRegulation)
    {
        startPage();
        List<LawRegulation> list = lawRegulationService.selectLawRegulationList(lawRegulation);
        return getDataTable(list);
    }

    /**
     * 导出法律法规列表
     */
    @PreAuthorize("@ss.hasPermi('system:lawRegulation:export')")
    @Log(title = "法律法规", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LawRegulation lawRegulation)
    {
        List<LawRegulation> list = lawRegulationService.selectLawRegulationList(lawRegulation);
        ExcelUtil<LawRegulation> util = new ExcelUtil<LawRegulation>(LawRegulation.class);
        util.exportExcel(response, list, "法律法规数据");
    }

    /**
     * 获取法律法规详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawRegulation:query')")
    @GetMapping(value = "/{lawId}")
    public AjaxResult getInfo(@PathVariable("lawId") Long lawId)
    {
        return success(lawRegulationService.selectLawRegulationByLawId(lawId));
    }

    /**
     * 新增法律法规
     */
    @PreAuthorize("@ss.hasPermi('system:lawRegulation:add')")
    @Log(title = "法律法规", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LawRegulation lawRegulation)
    {
        return toAjax(lawRegulationService.insertLawRegulation(lawRegulation));
    }

    /**
     * 修改法律法规
     */
    @PreAuthorize("@ss.hasPermi('system:lawRegulation:edit')")
    @Log(title = "法律法规", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LawRegulation lawRegulation)
    {
        return toAjax(lawRegulationService.updateLawRegulation(lawRegulation));
    }

    /**
     * 删除法律法规
     */
    @PreAuthorize("@ss.hasPermi('system:lawRegulation:remove')")
    @Log(title = "法律法规", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lawIds}")
    public AjaxResult remove(@PathVariable Long[] lawIds)
    {
        return toAjax(lawRegulationService.deleteLawRegulationByLawIds(lawIds));
    }
}
